package com.hanamaki.demo.testng;

import io.appium.java_client.android.AndroidDriver;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;

import java.net.MalformedURLException;
import java.net.URL;

public class AppiumTestNg {
    static AndroidDriver<WebElement> driver;
    @BeforeMethod
    public void setUp() throws MalformedURLException {
//        1. 创建配置对象   new
        DesiredCapabilities cp = new DesiredCapabilities();
//          添加配置信息
        cp.setCapability("deviceName", "127.0.0.1:62001");
        cp.setCapability("platformName", "Android");
        cp.setCapability("appPackage", "com.iBookStar.activityOff");
        cp.setCapability("appActivity", "com.iBookStar.activityOff.Splash");
//        如何启动？
//        驱动 对象
        URL url = new URL("http://localhost:4723/wd/hub");
//        注册 需要打开的 驱动 以及url 以及 对应的软件
        driver = new AndroidDriver<>(url, cp);
    }

    @Test
    public void test() throws InterruptedException {

//        如何 点击 开始体验？ 定位元素  ？  com.iBookStar.activityOff:id/go
//        注意时序问题
//        强制等待
        Thread.sleep(3000);
        WebElement id = driver.findElement(By.id("com.iBookStar.activityOff:id/go"));
        String text = id.getText();
        System.out.println(text);

        id.click();

    }

    @AfterMethod
    public void release() {
        driver.quit();
    }

}
